<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<link rel="stylesheet" type="text/css" href="../../../Themes/default/easyui.css">
		<link rel="stylesheet" type="text/css" href="../../../Themes/icon.css">
		<link rel="stylesheet" type="text/css" href="../../../CSS/demo.css">
		<link rel="stylesheet" type="text/css" href="../../../CSS/common.css">
		<style type="text/css">
			#fm {
				text-align: center;
			}
		</style>
	</head>

	<body style="padding:0px;background-color: white">

		<div id="toolbar" class="receipts_toolbar_style"></div>
		<div class="easyui-layout" data-options="fit:true" style="width: 98%;">
			<div id="searchOption" data-options="region:'north',title:'查询条件',split:true" style="height:150px;width:100%">

			</div>
			<div data-options="region:'center',split:true" style="width:100%;height: 200px;">
				<div class="easyui-panel" style="width:100%;height:100%;padding:0px;">
					<table id="dg" style="width: 100%;" class="table_style">
					</table>
				</div>
			</div>
			<div data-options="region:'south',title:'合计',split:true,collapsible:false" style="height:250px;padding: 10px">
				<table>
						<tbody>
							<tr>
								<th><b>订货单合计金额：</b></th>
								<td>
									<input style="border: none;" readonly="true" id="sum_number" name="sum_number">
								</td>
								<th><b>订货单合计金额(大写)：</b></th>
								<td>
									<input style="border: none;" readonly="true" id="dx_sum_number" name="dx_sum_number">
								</td>
								<th><b>出库金额汇总：</b></th>
								<td>
									<input style="border: none;" readonly="true" id="out_number" name="out_number">
								</td>
								<th><b>出库金额汇总(大写)：</b></th>
								<td>
									<input style="border: none;" readonly="true" id="dx_out_number" name="dx_out_number">
								</td>
							</tr>
							<tr>
								<th><b>收货金额汇总：</b></th>
								<td>
									<input style="border: none;" readonly="true" id="in_number" name="in_number">
								</td>
								<th><b>收货金额汇总(大写)：</b></th>
								<td>
									<input style="border: none;" readonly="true" id="dx_in_number" name="dx_in_number">
								</td>
							</tr>
						</tbody>
					</table>
			</div>
		</div>

		<div id="addFrame" class="easyui-dialog" closed="true" style="width:400px;height:400px;padding: 20px 10px;margin-left:;" data-options="title:'查询'">
			<form id="fm" style="margin: 0px 0px ;">
			</form>
		</div>

		<script type="text/javascript" src="../../../JS/jquery.min.js"></script>
		<script type="text/javascript" src="../../../JS/jquery.easyui.min.js"></script>
		<script type="text/javascript" src="../../../JS/common.js"></script>
		<script type="text/javascript" src="../../../JS/finance.js"></script>
		<script type="text/javascript" src="../../../JS/buildDialogSearch.js"></script>
		<script type="text/javascript">
			var globelOption = '';//保存查询参数
			var receipts_type = RECEIPT_SEARCH_SYMBOL;
			receipts_type += RECEIPT_EXPORT_SYMBOL;
			var toolbarList = AddReceiptsToolBar(receipts_type, "");
			$("#toolbar").append(toolbarList);

			var searchType = SEARCH_CREATE_TIME_START + SEARCH_CREATE_TIME_END + SEARCH_ORDER_NO;
			searchType += SEARCH_DISTRIBUTION_DATE_START_REQUIRE + SEARCH_DISTRIBUTION_DATE_END_REQUIRE + SEARCH_CUSTOMER_NAME + SEARCH_CUSTOMER_TYPE;
			$('#searchOption').append(constructSearchOptionFormat(searchType, ""));
			var content = buildSearchOptions(searchType, "");
			$("#fm").append(content);

			constructDataGridData();
			initCombobox();


			function constructDataGridData() {
				$('#dg').datagrid({
					method: 'get',
					rownumbers: 'true',
					autoRowHeight: 'true',
					fitColumns: 'false',
					singleSelect: 'true',
					columns: [
						[{
							field: 'INTERNAL_NAME',
							title: '内部商品名称',
							width: '8%',
							align: 'center',
						}, {
							field: 'INTERNAL_TYPE',
							title: '内部商品类型',
							width: '8%',
							align: 'center',
						},{
							field: 'AMOUNT',
							title: '订货单数量汇总',
							width: '8%',
							align: 'center'
						},{
							field: 'UNIT_NAME',
							title: '订货单位',
							width: '8%',
							align: 'center'
						}, {
							field:'SUM',
							title: '订货单金额汇总',
							width: '8%',
							align: 'center',
							formatter: function(value, row, index) {
								if(value !== '') {
									return value + '元'
								}
							}
						},{
							field:'WAREHOUSEOUT_AMOUNT',
							title: '出库数量汇总',
							width: '8%',
							align: 'center'
						},{
							field: 'INOUT_UNIT',
							title: '出库单位',
							width: '8%',
							align: 'center'
						},{
							field:'WAREHOUSEOUT_SUM',
							title: '出库金额汇总',
							width: '8%',
							align: 'center',
							formatter: function(value, row, index) {
								if(value !== '') {
									return value + '元'
								}
							}
						},{
							field: 'REAL_AMOUNT',
							title: '收货数量汇总',
							width: '8%',
							align: 'center'
						},{
							field: 'INOUT_UNIT',
							title: '收货单位',
							width: '8%',
							align: 'center'
						}, {
							field: 'REAL_SUM',
							title: '收货金额汇总',
							width: '8%',
							align: 'center',
							formatter: function(value, row, index) {
								if(value != '' && value != undefined) {
									return value + ' 元'
								}else{
									return '0  元'
								}
							}
						}]
					],

				});
			}

			function initCombobox() {
				$('#search_storehouse').combobox({
					valueField: 'NAME',
					textField: 'NAME',
					panelHeight: 200,
					mode: 'remote',
					method: 'get',
					editable: false,
					url: RemoteLinkAddress + "/logistics/storehouse/listall.do",
				});
				//配送单位
				$('#search_customr_name').combobox({
					valueField: 'CUSTOMER_NAME',
					textField: 'CUSTOMER_NAME',
					panelHeight: 200,
					mode: 'remote',
					method: 'get',
					url: RemoteLinkAddress + '/logistics/customer/listall.do',
					onChange: function(newValue, oldValue) {
						if(newValue != "" && newValue != undefined) {
							var url = RemoteLinkAddress + "/logistics/customer/findbypinyin?PINYINFIELDNAME=" + newValue.trim();
							$(this).combobox("reload", url);
						}
					}
				});
				//商品名称
				$('#search_commodity_name').combobox({
					valueField: 'INTERNAL_NAME',
					textField: 'INTERNAL_NAME',
					panelHeight: 200,
					mode: 'remote',
					method: 'get',
					url: RemoteLinkAddress + "/logistics/internaltrade/listall.do",
					onChange: function(newValue, oldValue) {
						if(!isEnglish(newValue)) {
							return;
						}
						if(newValue != "" && newValue != undefined) {
							var url = RemoteLinkAddress + "/logistics/internaltrade/findbypinyin?PINYINFIELDNAME=" + newValue.trim();
							$(this).combobox("reload", url);
						}
					},
				});
				//用户组
				$('#search_customer_type').combobox({
					valueField: 'CUSTOMER_TYPE',
					textField: 'CUSTOMER_TYPE',
					panelHeight: 200,
					mode: 'remote',
					method: 'get',
					url: RemoteLinkAddress + '/logistics/customertype/listall.do',
					onChange: function(newValue, oldValue) {
						if(newValue != "" && newValue != undefined) {
							var url = RemoteLinkAddress + "/logistics/customertype/findbypinyin?PINYINFIELDNAME=" + newValue.trim();
							$(this).combobox("reload", url);
						}
					},
					onSelect: function(record) {
						var _url = "";
						_url = RemoteLinkAddress + '/logistics/customer/listall.do?CUSTOMER_TYPE=' + record.CUSTOMER_TYPE;
						$('#search_customr_name').combobox("reload", _url);
					}
				});
			}

			function searchmore() {
				$('#addFrame').dialog({
					title: '查询',
					width: 400,
					height: 400,
				});
				$("#addFrame").dialog('open').dialog('center');
				$('#fm').form('clear');
			}

			function doSearch() {
				var isValid = $("#fm").form('validate');
				if(!isValid) {
					$.messager.alert("警告", "有必填项没有填写");
					return;
				}
				var searchCondition = processSearchCondition(true);
				globelOption = searchCondition;
				var _url = RemoteLinkAddress + '/logistics/financial/outrecievewastage.do?' + searchCondition;
				// $('#dg').datagrid('options').url = _url;
				// $('#dg').datagrid('reload');
				getRemoteData(_url)
				$('#addFrame').dialog('close');
			}
			//导出
			function exportExcel(){
				var _url = RemoteLinkAddress + '/logistics/financial/outrecievewastage/excel.do'
				if(globelOption.length > 0){
					_url += '?' + globelOption;
				}
				$.messager.confirm("提示", "确认导出Excel表格吗？", function(r) {
				if(r) {
					$.ajax({ //调用ajax方法，从服务器获取到该订单的所有数据
						type: "get",
						dataType: "json", //服务器返回的数据类型
						url: _url,
						success: function(result) {
							window.location.href = result.path;
						}, //请求成功后，接受服务器传来的Json字符串，并做相应的处理
						error: function(xhr, status, error) {
							$.messager.alert("错误", "请求失败!");
							}
						});
					}
				});
			}

			function getRemoteData(_url) {
				$.ajax({
					type: "get",
					url: _url,
					dataType: 'json',
					success: function(result) {
						$('#dg').datagrid('loadData', result.rows);
						var sum_number = result.SUM.toFixed(2);
						var out_number = result.WAREHOUSEOUT_SUM.toFixed(2);
						var in_number = result.REAL_SUM.toFixed(2);
						$('#sum_number').val('￥' + sum_number);//订货单合计金额：
						$('#out_number').val('￥' + out_number); //出库金额汇总：
						$('#in_number').val('￥' + in_number); //收货数量汇总：
						$('#dx_sum_number').val(changeMoneyToChinese(sum_number));
						$('#dx_out_number').val(changeMoneyToChinese(out_number));
						$('#dx_in_number').val(changeMoneyToChinese(in_number));

					},
					error: function(error) {

					}
				});
			}

			function closeForm() {
				$('#addFrame').dialog('close');
			}
		</script>
	</body>

</html>